package cn.tedu.coolshark01.user.service.impl;



import cn.tedu.coolshark01.base.exception.ServiceException;
import cn.tedu.coolshark01.base.response.StatusCode;
import cn.tedu.coolshark01.user.mapper.UserMapper;
import cn.tedu.coolshark01.user.pojo.dto.ProductQuery;
import cn.tedu.coolshark01.user.pojo.dto.UserLoginParam;
import cn.tedu.coolshark01.user.pojo.vo.ProductVO;
import cn.tedu.coolshark01.user.pojo.vo.UserVO;
import cn.tedu.coolshark01.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
//@Slf4j用来打日志
@Slf4j
//@Service用来标识当前类为业务层类
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;

    @Override
    public UserVO login(UserLoginParam userLoginParam) {
        log.debug("用户登录参数：{}", userLoginParam);
        UserVO userVO = userMapper.selectByUsername(userLoginParam.getUsername());
        if (userVO == null){
            throw new ServiceException(StatusCode.USERNAME_ERROR);
        }
        if (!userVO.getPassword().equals(userLoginParam.getPassword())){
            throw new ServiceException(StatusCode.PASSWORD_ERROR);
        }
        log.debug("用户查询结果：{}", userVO);
        return userVO;
    }

    @Override
    public List<ProductVO> selectproduct(ProductQuery productQuery) {
        log.debug("查询商品业务参数：{}", productQuery);
        List<ProductVO> list = userMapper.selectproduct(productQuery);
        log.debug("查询商品业务结果：{}", list);
        return list;
    }


}
